<?php
    include("html_header.html");
//include("html_footer.html");

//判断是否POST传递参数,注意区分大小写
    if ($_SERVER["REQUEST_METHOD"] != "POST") {
        echo("wrong request method");
        exit();
    }

    $user_id = $_POST['user_id'];
    $user_name = $_POST['user_name'];
    $user_passwd = $_POST['user_passwd'];
?>
    <script>
        $(document).ready(function () {

//            处理更新提交
            $("#btn_update").click(function (event) {
                event.preventDefault();

                $.post("user_update.php",
                    $("#mainForm").serialize(),
                    function (data) {
                        divRe = $("#div_result");
                        $("#div_result>p").detach();
                        divRe.hide();
                        divRe.append("<p>" + data + "</p>");
                        divRe.addClass("container");
                        divRe.fadeIn("slow");
                    });
            });

//            处理删除提交
            $("#btn_delete").click(function (event) {
                event.preventDefault();

                $.post("user_delete.php",
                    $("#mainForm").serialize(),
                    function (data) {
                        div = $("#div_result");
                        $("#div_result>p").detach();
                        div.hide();
                        div.append("<p>" + data + "</p>");
                        div.addClass("container");
                        div.fadeIn("slow");
                        $(document).location("")
                    });
            });

        });
    </script>
    <div id="mainContainer">
        <h1>资料修改</h1>

        <div class="container">
            <ul>
                <li><a href='index.php'>首页</a></li>
                <li><a href='user_list.php'>用户列表</a></li>
            </ul>
        </div>

        <div class="container">
            <form id="mainForm" class="mainTable">
                <label>User ID</label>
                <br>
                <input name="user_id" value="<?php echo($user_id); ?>" readonly="readonly"/>
                <br>
                <label>User Name</label>
                <br/>
                <input name="user_name" value="<?php echo($user_name); ?>"/>
                <br>
                <label>User Passwd</label>
                <br/>
                <input name="user_passwd" value="<?php echo($user_passwd); ?>"/>
                <br>
                <input id="btn_update" type='button' value="更新"/>
                <input id="btn_delete" type='button' value="删除"/>
            </form>
        </div>
        <div class="clear"></div>
        <div id="div_result"></div>
    </div>
<?php
//include("html_header.html");
    include("html_footer.html");
?>